package service.impl;/*
 *86180
 *2021/10/3
 *15:40
 */

import Dao.HealthDao;
import Dao.impl.HealthDaoImpl;
import entity.Health;
import service.HealthService;
import util.DruidUtil;
import util.Page;

import java.util.List;

public class HealthServiceImpl implements HealthService {
    private HealthDao healthDao = new HealthDaoImpl();
    @Override
    public List<Health> showAllHealth(Page page) {
        List<Health> healthList=null;
        healthList=healthDao.showAll(page);
        Long totalCount = healthDao.selectCount();
        page.setTotalCount(totalCount);
        DruidUtil.close();
        return healthList;
    }

    @Override
    public int addHealth(Health health) {
        int result=0;
        try {
            DruidUtil.begin();
            result=healthDao.insert(health);
            DruidUtil.commit();
        } catch (Exception e) {
            e.printStackTrace();
            DruidUtil.rollback();
        } finally {
            DruidUtil.close();
        }
        return result;
    }

    @Override
    public int updateHealth(Health health) {
        int result=0;
        try {
            DruidUtil.begin();
            result=healthDao.update(health);
            DruidUtil.commit();
        } catch (Exception e) {
            e.printStackTrace();
            DruidUtil.rollback();
        } finally {
            DruidUtil.close();
        }
        return result;
    }

    @Override
    public Health showHealthById(Integer id) {
        Health health=null;
        health=healthDao.select(id);
        DruidUtil.close();
        return health;
    }

    @Override
    public int deleteHealth(Integer id) {
        int result=0;
        try {
            DruidUtil.begin();
            result=healthDao.delect(id);
            DruidUtil.commit();
        } catch (Exception e) {
            e.printStackTrace();
            DruidUtil.commit();
        } finally {
            DruidUtil.close();
        }
        return result;
    }
}
